import { sm2 } from "sm-crypto";
export const sm2Utils = (data) => {
	try {
		let msg = data;
		// 转为字符串
		if (typeof data !== "string") {
			msg = JSON.stringify(data);
		}
		const publicKey =
			"02deb12446cb6fb5378cbb687e30d759ad38949580a5aeda4e9438d6f65615eba9";
		const privateKey =
			"3e26ab7e37ed62c0c1647be818fe10664560d8a9bb0fdb09bf181e98a12f019a";
		// 1 - C1C3C2, 0 - C1C2C3
		const cipherMode = 0;
		// 后端默认对字符串加了02，前端需要去除
		const enval = msg.substring(2);
		return sm2.doDecrypt(enval, privateKey, cipherMode);
	} catch {
		return "";
	}
};
